<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>实时告警监控</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<style type="text/css">
	    #authority table, caption, tbody, tfoot, thead, tr, th, td{
	        vertical-align: middle;
	    }
	</style>
	<script type="text/javascript">
	$(document).ready(function() {
		var totalId = $("#totalId").val();
        $("#totalLog").omGrid({
        	dataSource : 'alarmLog!findTotalList.do?totalId='+totalId,
            height : 580,
            limit : 20,
            showIndex : true,
            colModel : [ 
                         {header : '设备名称', name : 'device', width : 100, align : 'center',renderer : function(value){
                        	 if(value == null) {
                        		 return '';
                        	 }else{
                        		 return value.name;
                        	 }
                         }},
                         {header : '组织', name : 'device', width : 100, align : 'center',renderer : function(value){
                        	 if(value == null) {
                        		 return '';
                        	 }else{
                        		 return value.organization.name;
                        	 }
                         }},
                         {header : '告警时间', name : 'datetime', width : 140, align : 'center'},
                         {header : '告警分类', name : 'alarmClass', width : 70, align : 'center',renderer : function(value){
                        	 if(value == null) {
                        		 return '';
                        	 }else{
                        		 return value.name;
                        	 }
                         }},
                         {header : '告警级别', name : 'alarmClass', width : 70, align : 'center',renderer : function(value){
                        	 if(value == null) {
                        		 return '';
                        	 }else{
                        		 return value.level;
                        	 }
                         }},
                         {header : '告警内容', name : 'content', width : 200, align : 'left'},
                         {header : '处理状态', name : 'status', width : 70, align : 'center',renderer:function(value){
                             if(value == '0 '){
                            	 return '处理完毕';
                             }else if(value == '1 '){
                            	 return '未处理';
                             }else if(value == '2 '){
                            	 return '已确认';
                             }else if(value == '3 '){
                            	 return '已派修';
                             }else if(value == '-1') {
                            	 return '已清除';
                             }
                             return '未处理';
                         }}] 
        });
        $("#totalResetBtn").click(function() {
    		$('#totalName').val('');
    		$('#totalId').val('');
    		$("#totalLog").omGrid('setData','alarmLog!findTotalList.do');
    		countError('');
    	});
        
	});
	countError('');
    setInterval(intervalLog,1000*60);

	function intervalLog(){
		var totalId = $('#totalId').val();
		$("#totalLog").omGrid('reload');
		countError(totalId);
		findHdState(totalId);
	}
	function countError(id){
		$.ajax({
  			 url : 'alarmLog!countError.do',
  			 data : {totalId:id},
  			 dataType:'json',
  			 success : function(jsonData){
					 $("#alarmOne").text(jsonData.level0);
					 $("#alarmTow").text(jsonData.level1);
					 $("#alarmThree").text(jsonData.level2);
					 $("#alarmFour").text(jsonData.level3);
  			 }
  		 });
		
	}
	function totalAlarmLog(nodeData){
		$('#totalName').val(nodeData.text);
		$('#totalId').val(nodeData.id);
		 $("#totalLog").omGrid('setData','alarmLog!findTotalList.do?totalId='+nodeData.id);
		 countError(nodeData.id);
		 findHdState(nodeData.id);
	}
	
	function findHdState(idstr){
		var id;
		if(idstr){
			var type = idstr.substring(0,2);
			id = idstr.substring(3);
			if(type == 'de'){
				$.ajax({
		 			 url : 'alarmLog!findHdState.do',
		 			 data : {totalId:id},
		 			 dataType:'json',
		 			 success : function(data){
							 $("#logNetWork").text(data.onlineStatus == '0' ? '离线' : '在线');
							 $("#bandWidth").text(data.bandwidth == '' ? 0 : data.bandwidth);
							 $("#CPU").text(data.cpuocpy);
							 $("#dataVerson").text(data.hardwareversion);
							 $("#softVerson").text(data.softwareversion);
							 $("#deviceInfo").show();
							 $("#deviceVerson").show();
		 			 }
		 		 });
			}else{
				$("#deviceInfo").hide();
				 $("#deviceVerson").hide();
			}
			}
	}
	</script>  
  </head>
  
  <body>
	<div class="select_table">
		<table   cellpadding="1" cellspacing="1" class="layout"  border="0">
	          <tr>
	            <td width="15%" align="left">区域/组织/设备：</td>
	            <td width="5%">
	            	<input name="totalName" id="totalName" type="text" readonly="readonly" value="" size="20"/>
	            	<input name="totalId" id="totalId" type="hidden"/>
	            </td>
	            <td width="15%"><font color="red">*点击右侧菜单选择</font>&nbsp;</td>
	            <td>
	            	<button class="button_u" id="totalResetBtn" onmousemove="this.className='button_f'" onmousedown="this.className='button_d'" onmouseout="this.className='button_u'">重置</button></td>
	          </tr>
	          <tr>
	          	<td colspan="4">&nbsp;</td>
	          </tr>
	          <tr>
	          	<td>1级告警：<span id="alarmOne" style="color: red;"></span></td>
	          	<td>2级告警：<span id="alarmTow" style="color: red;"></span></td>
	          	<td>3级告警：<span id="alarmThree"  style="color: red;"></span></td>
	          	<td>4级告警：<span id="alarmFour" style="color: red;"></span></td>
	          </tr>         
		          <tr id="deviceInfo" style="display: none;">
		          	<td>网络：<span id="logNetWork"></span></td>
		          	<td>带宽：<span id="bandWidth"></span>M</td>
		          	<td colspan="2">CUP占用：<span id="CPU"></span>%</td>
		          </tr>
		          <tr id="deviceVerson" style="display: none;">
		          	<td colspan="2">数据版本号：<span id="dataVerson"></span></td>
		          	<td colspan="2">软件版本号：<span id="softVerson"></span></td>
		          </tr>
	    </table>
	</div>
    <table id="totalLog"></table>
  </body>
</html>
